package 用栈实现队列;

import java.util.Stack;

public class MyQueue {
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    // 入栈
    public void push(int x) {
        stack1.push(x);
    }

    // 出栈
    public int pop() {
        if (empty()) {
            return -1;
        }
        if (stack2.isEmpty()) {
            int size1 = stack1.size()-1;
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    public int peek() {
        if (empty()) {
            return -1;
        }
        if (stack2.isEmpty()) {
            int size1 = stack1.size()-1;
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }

    public boolean empty() {
        if (stack1.isEmpty() && stack2.isEmpty()) {
            return true;
        }
        return false;
    }


}
